#!/usr/bin/env python3
# Francesco Conti <f.conti@unibo.it>
#
# Copyright (C) 2016-2018 ETH Zurich, University of Bologna.
# All rights reserved.

from ipstools_cfg import *
import argparse
import sys

parser = argparse.ArgumentParser(
    prog='PULP update script',
    description="""Fetch IPs and resolve dependencies for PULPissimo""")

parser.add_argument('--rt-dpi', action='store_true',
                    help='Use the PULP Runtime DPI to emulate peripherals')
parser.add_argument('--i2c-vip', action='store_true',
                    help="""Use the i2c model (24FC1025).
                    Needs to be installed.""")
parser.add_argument('--flash-vip', action='store_true',
                    help="""Use the flash model (S25FS256).
                    Needs to be installed.""")
parser.add_argument('--i2s-vip', action='store_true',
                    help="""Use the i2s model (24FC1025).
                    Needs to be installed.""")
parser.add_argument('--verbose', action='store_true',
                    help='Show more information about commands')

args = parser.parse_args()

try:
    os.mkdir("ips")
except OSError:
    pass
# creates an IPApproX database
ipdb = ipstools.IPDatabase(
    skip_scripts=True,
    build_deps_tree=True,
    resolve_deps_conflicts=True,
    rtl_dir='rtl',
    ips_dir='ips',
    vsim_dir='sim',
    default_server=DEFAULT_SERVER,
    verbose=args.verbose
)
# updates the IPs from the git repo
ipdb.update_ips()

# launch generate-ips.py
ipdb.save_database()

# pass arguments and call generate script
execute("./generate-scripts " + (' '.join(sys.argv[1:])))

